package edu.ecust.design.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.ecust.design.cons.AccountStatus;
import edu.ecust.design.dao.AccountMapper;
import edu.ecust.design.domain.Account;
import edu.ecust.design.domain.AccountExample;
import edu.ecust.design.domain.AccountExample.Criteria;
import edu.ecust.design.service.IAccountService;
import edu.ecust.design.utils.AccountUtils;

@Service
public class AccountServiceImpl implements IAccountService {
	@Autowired
	private AccountMapper accountMapper;

	@Override
	public Account checkAccount(String userName, String pwd) {
		if (StringUtils.isBlank(userName)) {
			return null;
		}
		if (StringUtils.isBlank(pwd)) {
			return null;
		}
		AccountExample ae = new AccountExample();
		Criteria cri = ae.createCriteria();
		cri.andUserNameEqualTo(userName);
		cri.andPasswordEqualTo(AccountUtils.MD5(pwd));
		cri.andStatusEqualTo(AccountStatus.normal.getId());
		List<Account> list = accountMapper.selectByExample(ae);
		if (list.size() > 0) {
			return list.get(0);
		}
		return null;
	}
}
